package cn.lg.soar.system.auth.entity;

import cn.lg.soar.common.data.tree.ITreeSource;
import cn.lg.soar.core.util.easyexcel.converters.BooleanConverter;
import cn.lg.soar.database.base.entity.ITenantEntity;
import cn.lg.soar.database.base.entity.NumberTreeEntity;
import cn.lg.soar.database.translate.TranslateByEntity;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Objects;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ExcelIgnoreUnannotated
@Getter
@Setter
@Accessors(chain = true)
@ApiModel(value="Role对象", description="角色信息表")
@TableName("lg_sys_role")
public class Role extends NumberTreeEntity<Long> implements ITenantEntity, ITreeSource<Long> {

    private static final long serialVersionUID = -4829935907047172542L;

    @TableId
    private Long id;

    @ColumnWidth(18)
    @ExcelProperty(value = "code", index = 0)
    private String code;

    @ExcelProperty(value = "类型", index = 1)
    private Integer type;

    @ColumnWidth(18)
    @ExcelProperty(value = "名称", index = 2)
    private String name;

    @ColumnWidth(18)
    @ExcelProperty(value = "别名(简称)", index = 3)
    private String alias;

    @ColumnWidth(18)
    @ExcelProperty(value = "备注", index = 4)
    private String remark;

    @ExcelProperty(value = "是否禁用", converter = BooleanConverter.class)
    private Boolean disabled;

    @ApiModelProperty(value = "租户id")
    @JsonIgnore
    @TableField(select = false)
    private Integer tenantId;

    @Version
    @ApiModelProperty(value = "乐观锁")
    protected Integer version;

    @TranslateByEntity(Role.class)
    @Override
    public Long getParentId() {
        return parentId;
    }

    @JsonIgnore
    @Override
    public Long primaryKey() {
        return this.id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        Role role = (Role) o;
        return Objects.equals(id, role.id) ||
                Objects.equals(code, role.code);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), id, code);
    }
}
